<h3>Attendance Timings for the month of <?php echo date("F",mktime(0, 0, 0,$month, 10));?></h3>
<div class="row-fluid">

<div class="span10">
<div class="span2" >
<table class="table table-condensed table-striped" style="font-size: 10px;">
<thead>
	<tr>
		<th width="200">Name</th>
		
		</tr>
		</thead>
		<?php foreach($attendance_details as $attendance_detail):?>
	<tr>
	<td>
	<?php 
	//$edited_date = $this->attendance_model->check_edit_attendance($attendance_details->user_id,$attendance_details->year_id,$attendance_details->month_id); 
	//print_r($edited_date);
	?>
	<?= $attendance_detail->first_name;?>
	<span class="pull-right"><a class="tooltips" title="Attendance" data-placement="top" href="<?php echo site_url('founder/attendance/index/'.$attendance_detail->user_id.'/'.$attendance_detail->year_id.'/'.$month);?>">
		<i class="icon-medkit"></i>	</a>	
	<a class="tooltips" title="Worksheet" data-placement="right" href="<?php echo site_url('user/worksheet/index/'.$attendance_detail->user_id.'/'.$attendance_detail->year_id.'/'.$month);?>">
		<i class="icon-tasks"></i>		</a>
		</span>
	</td></tr>
	<?php endforeach;?>
		</table>	
	
</div>
<div class="span10" style="overflow: scroll; overflow-y: hidden;margin-left: 0px;">
<table class="table table-condensed table-striped">
	<tr>
		<!--<th width="200">Name</th>-->
		<?php for($i=1;$i<=31;$i++){
		if($i<10)
		{		
		$date_id = '0'.$i;
		}
		else{		
		$date_id = $i;
		}	
			
			?>
		<th><?= $date_id?></th>			
		<?php }?>
		<th>Average</th>
		<th>PL</th>
		<th>UL</th>
		<th>Absent</th>
	</tr>	
	
	<?php foreach($attendance_details as $attendance_details){
		$present_days = 0;
		$total_time = 0;
		$paid_leave = 0;
		$unpaid_leave = 0;
		$absent_leave = 0;
		?>
	<tr>	
	<?php for($y=1;$y<=31;$y++){
		if($y<10)
		{
		 $day = 'day_0'.$y;	
		$date_id = '0'.$y;
		}
	else{
		$day = 'day_'.$y;
		$date_id = $y;
		}	
			
	?>
	<td <?php 
	$edited_date = $this->attendance_model->check_edit_attendance($attendance_details->user_id,$attendance_details->year_id,$attendance_details->month_id);
	
	//getting the ip of all entries.	
	//$get_ip = $this->attendance_model->check_ip_date($attendance_details->user_id,$date_id,$attendance_details->month_id,$attendance_details->year_id);
	/*print_r($get_ip);*/
	
	//getting ip from database
	/*foreach($get_ip as $gi){		
		if(!($dip = $this->attendance_model->check_ip(ip2long($gi->entry_ip)))){
			echo ' style="color:red" ';
		}elseif(!($dip = $this->attendance_model->check_ip(ip2long($gi->lunch_in_ip)))){
			echo ' style="color:red" ';
		}elseif(!($dip = $this->attendance_model->check_ip(ip2long($gi->lunch_out_ip)))){
			echo ' style="color:red" ';
		}elseif(!($dip = $this->attendance_model->check_ip(ip2long($gi->exit_ip)))){
			echo ' style="color:red" ';
		}		
	}*/
	
	if($attendance_details->$day=='sunday'){
	echo ' style="background-color:#990000" ';	
	}
	
	foreach($edited_date as $edited_date){		
	//echo $edited_date->date_id;
//	echo $attendance_details->$day;
	if($edited_date->date_id == $date_id){
		echo 'class = "text-warning"';
		}
	}
	/*if($edited_date == $attendance_details->$day){
		echo 'class = "text-warning"';
	}*/
	?> 
	>
		
	<?php if($attendance_details->$day=='sunday'):?>
	<?php else: ?>	
	<?php 
	//echo is_string($attendance_details->$day);
	if(isset($attendance_details->$day)and !empty($attendance_details->$day)){		
	
	echo $attendance_details->$day;
	
	$paid_leave_select = array('paid_leave');
	
	if(in_array($attendance_details->$day,$paid_leave_select))
		{
			$paid_leave +=1 ;	
		}
	
	$unpaid_leave_select = array('unpaid_leave');
	
	if(in_array($attendance_details->$day,$unpaid_leave_select))
		{
			$unpaid_leave +=1 ;	
		}

	$absent_leave_select = array('absent');
	
	if(in_array($attendance_details->$day,$absent_leave_select))
		{
			$absent_leave +=1 ;	
		}	
	
	$no_calculation = array('unpaid_leave','holiday','paid_leave','absent');
	
	if(!in_array($attendance_details->$day,$no_calculation)){
	
	$present_days +=1 ;	
	$pos = strpos($attendance_details->$day, ':');
	if($pos){	
	$time_explode = explode(':',$attendance_details->$day);		
		$tot_hr		 	= $time_explode[0]*60*60;
		$tot_min 		= $time_explode[1]*60;
		$tot 			= $tot_hr + $tot_min;
		$total_time	 	+= $tot;
			}
		}
	 }
	 ?>		 
	<?php endif;?>		
	</td>
	<?php } ?>	
	<td>
	<?php
		if($present_days > 0){	
		//echo($present_days);
$avg_time = $total_time / $present_days;
$hr = floor($avg_time / 3600);
$min = floor(($avg_time / 60) % 60);
echo $hr.':'.$min;	
}else{
	echo '0';	
}?>
		
	</td>
	
<td>
<?php 
echo($paid_leave);	
?>
</td>
<td>
<?php 
echo($unpaid_leave);	
?>
</td>
<td>
<?php 
echo($absent_leave);	
?>
</td>	
	
	</tr>
	<?php }?>
	
		
	
</table>

</div>
</div>
<div class="span2">
	<header>Actions</header>	
		<div>
		
		<?php foreach($year_lst as $year_lst)
			{ 
	?>
	<div class="accordion" id="accordion1">
		<div class="accordion-group">
			<div class="accordion-heading">
				<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapse<?php echo($year_lst->year_id);?>">
					<?php echo("20" . $year_lst->year_id);?>	
				</a>
			</div>
			<div id="collapse<?php echo($year_lst->year_id);?>" class="accordion-body collapse <?php $year_info = getdate();$current_year ="20" . $year_lst->year_id; if(($year_info['year']) == $current_year) {echo("in");}?>">
				<div class="accordion-inner">
					<?php $month_lst = $this->all_attendance_model->get_worksheet_months($year_lst->year_id);?>
					
					<ul>
					<?php foreach($month_lst as $month_lst){ ?>
					<li>	
					<a href="<?php echo site_url('founder/attendance/attendance_details').'/'.$year_lst->year_id.'/'.$month_lst->month_id?>"><?= date("F", mktime(0, 0, 0, $month_lst->month_id, 10))?></a>			
					</li>
					<?php }?>
					</ul>
					
				</div>
			</div>
		</div>
	</div>	
	
	<?php }?>
</div>
</div>


<br /><br />
<div>
<h4 class="widget-name">IP for attendance</h4>
	<form class="form-inline" action="<?php echo site_url('founder/attendance/save_ip');?>" method="POST">
	  <input type="text" class="input" placeholder="IP From " name="from_ip">
	  <input type="text" class="input" placeholder="IP To"  name="to_ip">
	  
	  <button type="submit" class="btn btn-danger">Save IP</button>
</form>	

<table class="table table-bordered">
	<tr>
		<th>From</th>
		<th>To</th>		
		<th>Action</th>
	</tr>
	<?php foreach($ips as $ip){ ?>
	<tr>
		<td><?php echo long2ip($ip->from_ip); ?></td>
		<td><?php echo long2ip($ip->to_ip); ?></td>
		<td><a href="javascript:void(0)" onclick="delete_ip(<?php echo $ip->id;?>)"><i class="icon-trash"></i> </a></td>
	</tr>
	<?php }?>
</table>

</div>
<script type="text/javascript">
<!--
	function delete_ip(id){
		var r = confirm("Are you sure you want to delete");
		if(r==true){		
		$.post('<?= site_url('founder/attendance/delete_ip');?>',
				{id:id}, function(data)
				{				
				window.location.reload();
				})
			}				
	}
//-->
</script>

